/*
 *  hyperelasticinvariants.h
 *  EPPI-0.0
 *
 *  Created by Sergio Conde Martin on 1/04/11.
 *
 */
 
#ifndef _hyperelasticinvariants_h_
#define _hyperelasticinvariants_h_

#include <iostream>
#include "MATERIALS/material.h"

using namespace std;

class HyperelasticInvariants : public Material
{
public:	

	double W1;	// First derivative of Strain Energy respect to the first invariant
	double W2;	// First derivative of Strain Energy respect to the second invariant
	double W3;	// First derivative of Strain Energy respect to the third invariant
	
	double W11;	// Second derivative of Strain Energy respect to the first invariant
	double W12;     // Second crossed derivative of Strain Energy respect to the first invariant and to the second invariant
	double W13;	// Second crossed derivative of Strain Energy respect to the first invariant and to the third invariant
	double W22;	// Second derivative of Strain Energy respect to the second invariant
	double W23;	// Second crossed derivative of Strain Energy respect to the second invariant and to the third invariant
	double W33;	// Second derivative of Strain Energy respect to the third invariant
	
	double Wvol;	// Volumetric Strain Energy function which depends on the volume ratio J
	
	double dWvol;	// First derivative of Strain Energy respect to the volume ratio J
	double ddWvol;	// Second derivative of Strain Energy respect to the volume ratio J
	
	//double Wiso;	// Isochoric Strain Energy function which depends on the modified right Cauchy-Green tensor: Cm
	
	double Wiso1;	// First derivative of Isochoric Strain Energy respect to the first modified invariant(Im)
	double Wiso2;	// First derivative of Isochoric Strain Energy respect to the second modified invariant(IIm)
	
	double Wiso11;	// Second derivative of Isochoric Strain Energy respect to the first invariant
	double Wiso12;	// Second crossed derivative of Isochoric Strain Energy respect to the first modified invariant and to the second modified invariant
	double Wiso22;	// Second derivative of Isochoric Strain Energy respect to the second invariant
	
    // Viscoelasticity Tensor
    double kappa11, kappa12, kappa21, kappa22, kappa31, kappa32, kappa41, kappa42;
    double Wiso111, Wiso112, Wiso122;
    double Wiso222, Wiso221, Wiso211;

private:

	Matrix3d SMat, SvolMat;

	// Elasticity Tensor
	double delta1, delta2, delta3, delta4;
	Tensor2Sym SisoTens, mSisoTens;                 //
	Tensor4LSym  mCtisoTens, CtTens, CtisoTens;
    

	
public:
	HyperelasticInvariants();
	HyperelasticInvariants(const string &, const string &);
	~HyperelasticInvariants(){}
	
	/** Virtual functions from base */
	
	void calcInvariants ( const VectorXd & );

	void calcW( const VectorXd & );		// Computes the hyperelastic free energy function

	void calcS( const VectorXd & );		// Computes the Second Piola-Kirchoff Stress Tensor
	void calcSvol( const VectorXd &);   // Computes the volumetric part of the Second Piola-Kirchoff Stress Tensor
	void calcSiso( const VectorXd & );	// Computes the isochoric part of the Second Piola-Kirchoff Stress Tensor

	void calcCt( const VectorXd & );	// Computes the constitutive material tensor

	// Useful tools
    
	void calcCTensor( const VectorXd &);
    void calcCiTensor( const VectorXd &);
    void calcP( const VectorXd &);
    void calcPt( const VectorXd &);
    void calctildeP( const VectorXd &);
	
	/** Local functions */
		
	/** Virtual functions which defines the materials */
	virtual void strainEnergy()=0;		// Strain energy
	virtual void DstrainEnergy()=0;		// First derivative of Strain energy respect to the invariants
	virtual void DDstrainEnergy()=0;	// Second derivative of Strain energy respect to the invariants
    virtual void DDDstrainEnergy()=0;	// Third derivative of Strain energy respect to the invariants
};

#endif	
	
